package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tanhua.dubbo.mappers.BlackListMapper;
import com.tanhua.dubbo.mappers.UserInfoMapper;
import com.tanhua.model.domain.BlackList;
import com.tanhua.model.domain.UserInfo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import javax.management.Query;

@DubboService
public class BlackListApiImpl implements BlackListApi{

    @Autowired
    private BlackListMapper blackListMapper;

    @Autowired
    private UserInfoMapper userInfoMapper;

    @Override
    public IPage<UserInfo> findByUserId(Long userId, int page, int size) {
        // 构建分页参数对象 Page
        Page pages = new Page(page,size);

        // 调用方法分页
        return userInfoMapper.findBlackList(pages,userId);

    }

    @Override
    public void delete(Long userId, Long blackUserId) {
        QueryWrapper<BlackList> blackListQueryWrapper = new QueryWrapper<>();
        blackListQueryWrapper.eq("user_id",userId);
        blackListQueryWrapper.eq("black_user_id",blackUserId);
        blackListMapper.delete(blackListQueryWrapper);
    }
}
